﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hotel.Models.Entity;
using Hotel.Models.Services;

namespace Hotel.Controllers
{
    public class StaffController : BaseController
    {
        //
        // GET: /Staff/

        public ActionResult Staff()
        {
            List<Staff> lstaff = StaffService.GetListStaff();
            List<GroupStaff> lgstaff = GroupStaffService.GetListGroupStaff();
            ViewData["ListGroupStaff"] = lgstaff;
            ViewData["ListStaff"] = lstaff;
            return View();
        }
        [HttpPost]
        public bool AddGroupStaff(string name, string note, int grouppolicy)
        {
            GroupStaff gst = new GroupStaff();
            gst.Name = name;
            gst.Note = note;
            gst.Authorities = grouppolicy;
            return GroupStaffService.SaveGroupStaff(gst, false);
        }
        [HttpPost]
        public bool EditGroupStaff(int id, string name, string note, int grouppolicy)
        {
            GroupStaff gst = GroupStaffService.GetDetailGroupStaff(id);
            gst.Name = name;
            gst.Note = note;
            gst.Authorities = grouppolicy;
            return GroupStaffService.SaveGroupStaff(gst, true);
        }
        [HttpPost]
        public bool AddStaff(int groupstaffid, string username, string password, string fullname, string address, string phone, string email, string passport, string birthdate, string whereborn, string tamtru, string thuongtru, string datejoin, string salary, string note, int dateperweek, int policy)
        {
            Staff st = new Staff();
            GroupStaff gst = GroupStaffService.GetDetailGroupStaff(groupstaffid);
            st.GroupStaff = gst;
            st.UserName = username;
            st.PassWord = password;
            st.Name = fullname;
            st.Address = address;
            st.Phone = phone;
            st.Email = email;
            st.Passport = passport;
            DateTime birthday;
            birthday = !string.IsNullOrEmpty(birthdate) ? Convert.ToDateTime(birthdate) : DateTime.Now;
            st.BirthDay = birthday;
            st.BirthPlace = whereborn;
            st.Sojourn = tamtru;
            st.Wage = !string.IsNullOrEmpty(salary)?Convert.ToDouble(salary) : 0;
            st.Resident = thuongtru;
            DateTime dateEntry;
            dateEntry = !string.IsNullOrEmpty(datejoin) ? Convert.ToDateTime(datejoin) : DateTime.Now;
            st.DateEntry = dateEntry;
            st.WorkingDay = dateperweek;
            st.Note = note;
            st.Authorities = policy;
            return StaffService.SaveStaff(st, false);
        }
        [HttpPost]
        public bool EditStaff(int id, int groupstaffid, string username, string password, string fullname, string address, string phone, string email, string passport, string birthdate, string whereborn, string tamtru, string thuongtru, string datejoin, string salary, string note, int dateperweek, int policy)
        {
            GroupStaff gst = GroupStaffService.GetDetailGroupStaff(groupstaffid);
            Staff st = StaffService.GetDetailStaff(id);
            st.GroupStaff = gst;
            st.UserName = username;
            st.PassWord = password;
            st.Name = fullname;
            st.Address = address;
            st.Phone = phone;
            st.Email = email;
            st.Passport = passport;
            DateTime birthday;
            birthday = !string.IsNullOrEmpty(birthdate) ? Convert.ToDateTime(birthdate) : DateTime.Now;
            st.BirthDay = birthday;
            st.BirthPlace = whereborn;
            st.Sojourn = tamtru;
            st.Wage = !string.IsNullOrEmpty(salary)?Convert.ToDouble(salary) : 0;
            st.Resident = thuongtru;
            DateTime dateEntry;
            dateEntry = !string.IsNullOrEmpty(datejoin) ? Convert.ToDateTime(datejoin) : DateTime.Now;
            st.DateEntry = dateEntry;
            st.WorkingDay = dateperweek;
            st.Note = note;
            st.Authorities = policy;
            return StaffService.SaveStaff(st, true);
        }
    }
}
